home *** CD-ROM | disk | FTP | other *** search
/ Champak 139 / (Vol 139) Sep 24 2011.iso / Games / sheep_are_save.swf / scripts / frame_1 / DoAction.as < prev   
Text File  |  2011-09-24  |  15KB  |  765 lines

  1. function min(a, b)
  2. {
  3.    if(a < b)
  4.    {
  5.       return a;
  6.    }
  7.    return b;
  8. }
  9. function playSnd(lib_snd)
  10. {
  11.    s = new Sound(this);
  12.    s.attachSound(lib_snd);
  13.    s.start();
  14. }
  15. function stopMySound()
  16. {
  17.    stopSoundFlag = true;
  18.    mc_sloop.gotoAndStop(3);
  19. }
  20. function startMySound()
  21. {
  22.    stopSoundFlag = false;
  23.    if(!pauseFlag)
  24.    {
  25.       mc_sloop.gotoAndStop(2);
  26.    }
  27. }
  28. function startGame()
  29. {
  30.    level = 0;
  31.    nextLevel();
  32.    set("/gametablo:scores",0);
  33.    setProperty("/gametablo", _visible, true);
  34. }
  35. function gameOver()
  36. {
  37.    this.gotoAndPlay("lamo");
  38.    mc_sloop.gotoAndStop(3);
  39. }
  40. function gameWin()
  41. {
  42.    set("/gametablo:scores",Number(eval("/gametablo:scores")) + scrLevel);
  43.    this.gotoAndStop("rul");
  44.    mc_sloop.gotoAndStop(3);
  45. }
  46. function nextLevel()
  47. {
  48.    this.gotoAndStop("startgame");
  49.    if(!stopSoundFlag)
  50.    {
  51.       mc_sloop.gotoAndStop(2);
  52.    }
  53. }
  54. function newGame()
  55. {
  56.    setProperty("/Game", _visible, 0);
  57.    this.Stop();
  58.    setProperty("/Rating", _visible, 1);
  59.    tellTarget("/Rating")
  60.    {
  61.       gotoAndStop("Save");
  62.    }
  63.    stop();
  64. }
  65. function startPause()
  66. {
  67.    pauseFlag = true;
  68.    mc_sloop.gotoAndStop(3);
  69.    m1.pG.stop();
  70.    i = 1;
  71.    while(wfC >= i)
  72.    {
  73.       wfA[i].pGo.stop();
  74.       wfA[i].pGl.stop();
  75.       i++;
  76.    }
  77. }
  78. function stopPause()
  79. {
  80.    pauseFlag = false;
  81.    if(!stopSoundFlag)
  82.    {
  83.       mc_sloop.gotoAndStop(2);
  84.    }
  85.    m1.pG.play();
  86.    i = 1;
  87.    while(wfC >= i)
  88.    {
  89.       wfA[i].pGo.play();
  90.       wfA[i].pGl.play();
  91.       i++;
  92.    }
  93. }
  94. stopSoundFlag = false;
  95. mP = 57.29577951308232;
  96. mPo = 0.017453292519943295;
  97. h2 = 16;
  98. h22 = 24;
  99. Sheep = function(parent, num, minSpeed, maxSpeed, rotateSpeed, wayLong, rotateLong, runInCenter)
  100. {
  101.    this.p = parent;
  102.    this.numL = num;
  103.    this.minS = minSpeed;
  104.    this.maxS = maxSpeed;
  105.    this.riS = runInCenter;
  106.    this.cS = 0;
  107.    this.rtS = rotateSpeed;
  108.    this.rtD = 1;
  109.    this.wL = wayLong;
  110.    this.wC = 0;
  111.    this.rtL = rotateLong;
  112.    this.vx = 0;
  113.    this.vy = 0;
  114.    this.fx = this.p._x;
  115.    this.fy = this.p._y;
  116.    this.st = 0;
  117.    this.tdT = 3;
  118. };
  119. Sheep.prototype.sGo = function()
  120. {
  121.    saC++;
  122.    if(random(3) == 0)
  123.    {
  124.       this.st = 2;
  125.       if(random(2) == 0)
  126.       {
  127.          this.rtD = 1;
  128.       }
  129.       else
  130.       {
  131.          this.rtD = -1;
  132.       }
  133.    }
  134.    else
  135.    {
  136.       this.st = 1;
  137.       this.cS = random(this.maxS - this.minS) + this.minS;
  138.       this.vx = Math.sin(this.p._rotation * mPo);
  139.       this.vy = - Math.cos(this.p._rotation * mPo);
  140.    }
  141.    this.wC = 0;
  142. };
  143. Sheep.prototype.calcXY = function()
  144. {
  145.    if(this.st == 1)
  146.    {
  147.       this.fx = this.p._x + this.vx * this.cS;
  148.       this.fy = this.p._y + this.vy * this.cS;
  149.    }
  150. };
  151. Sheep.prototype.goto = function()
  152. {
  153.    this.wC = this.wC + 1;
  154.    if(this.st == 1)
  155.    {
  156.       this.p._x = this.fx;
  157.       this.p._y = this.fy;
  158.       with(this)
  159.       {
  160.          if(p._x < 0 || 520 < p._x || p._y < 0 || 390 < p._y)
  161.          {
  162.             die();
  163.          }
  164.       }
  165.       if(this.wL < this.wC)
  166.       {
  167.          this.st = 0;
  168.          saC--;
  169.       }
  170.    }
  171.    else if(this.st == 2)
  172.    {
  173.       this.p._rotation += this.rtD * this.rtS;
  174.       if(this.rtL < this.wC)
  175.       {
  176.          this.st = 0;
  177.          saC--;
  178.       }
  179.    }
  180.    if(this.st == 3)
  181.    {
  182.       if(this.wC >= this.tdT)
  183.       {
  184.          this.die();
  185.       }
  186.    }
  187. };
  188. Sheep.prototype.r90 = function()
  189. {
  190.    if(random(2) == 0)
  191.    {
  192.       k = 1;
  193.    }
  194.    else
  195.    {
  196.       k = -1;
  197.    }
  198.    this.vx = (- this.vy) * k;
  199.    this.vy = this.vx * k;
  200.    this.p._rotation = Math.atan2(this.vx,- this.vy) * mP;
  201. };
  202. Sheep.prototype.hT = function(obj)
  203. {
  204.    if(Math.abs(this.fx - obj._x) < h2 && Math.abs(this.fy - obj._y) < h2)
  205.    {
  206.       return true;
  207.    }
  208.    return false;
  209. };
  210. Sheep.prototype.boom = function()
  211. {
  212.    if(this.st == 1 || this.st == 2)
  213.    {
  214.       saC--;
  215.    }
  216.    this.st = 3;
  217.    this.wC = 0;
  218.    nn.mc_boom.duplicateMovieClip("pBoom",1000 + this.numL);
  219.    with(nn.pBoom)
  220.    {
  221.       _visible = true;
  222.       _x = this.p._x;
  223.       _y = this.p._y;
  224.    }
  225. };
  226. Sheep.prototype.die = function()
  227. {
  228.    if(this.st == 1 || this.st == 2)
  229.    {
  230.       saC--;
  231.    }
  232.    with(this)
  233.    {
  234.       st = 4;
  235.       p._visible = false;
  236.       p._x = p._y = -1000;
  237.    }
  238.    saD++;
  239. };
  240. Sheep.prototype.run = function()
  241. {
  242.    if(this.st == 0)
  243.    {
  244.       saC++;
  245.    }
  246.    with(this)
  247.    {
  248.       wC = 0;
  249.       st = 1;
  250.       cS = riS;
  251.    }
  252.    with(this)
  253.    {
  254.       tmpI = Math.atan2(p._x - 260,p._y - 195) * mP;
  255.       p._rotation = - tmpI;
  256.       vx = Math.sin(p._rotation * mPo);
  257.       vy = - Math.cos(p._rotation * mPo);
  258.    }
  259.    playSnd("lib_sheep");
  260. };
  261. Wolf = function(baseLevel, pNum, minSpeed, maxSpeed, pauseTime, goTime, dieTime, glukTime, glukAmount)
  262. {
  263.    this.name = "w" add pNum;
  264.    nn.attachMovie("lib_wolf",this.name,baseLevel + pNum * 3 + 1);
  265.    nn.attachMovie("lib_wolf_Go",this.name + "g",baseLevel + pNum * 3);
  266.    nn.attachMovie("lib_wolf_gluk",this.name + "gl",baseLevel + pNum * 3 + 2);
  267.    tellTarget("nn." + this.name)
  268.    {
  269.       _X = _Y = -2000;
  270.       c1._visible = c2._visible = _visible = false;
  271.    }
  272.    tellTarget("nn." + this.name + "g")
  273.    {
  274.       _X = _Y = 0;
  275.       c1._visible = c2._visible = _visible = false;
  276.    }
  277.    tellTarget("nn." + this.name + "gl")
  278.    {
  279.       _X = _Y = 0;
  280.       c1._visible = c2._visible = _visible = false;
  281.    }
  282.    this.p = eval("nn." + this.name);
  283.    this.pGo = eval("nn." + this.name + "g");
  284.    this.pGl = eval("nn." + this.name + "gl");
  285.    this.vx = 0;
  286.    this.vy = 0;
  287.    this.minS = minSpeed;
  288.    this.maxS = maxSpeed;
  289.    this.cS = 0;
  290.    this.st = 0;
  291.    this.pT = pauseTime;
  292.    this.gT = goTime;
  293.    this.pC = 0;
  294.    this.sF = true;
  295.    this.dT = dieTime;
  296.    this.glT = glukTime;
  297.    this.glA = glukAmount;
  298.    this.glC = 0;
  299. };
  300. Wolf.prototype.rem = function()
  301. {
  302.    removeMovieClip("nn." + this.name);
  303. };
  304. Wolf.prototype.sGo = function()
  305. {
  306.    with(this)
  307.    {
  308.       cS = random(maxS - minS) + minS;
  309.    }
  310.    tmpI = random(360);
  311.    this.vx = Math.sin(tmpI * mPo);
  312.    this.vy = Math.cos(tmpI * mPo);
  313.    a = 60;
  314.    k = Math.abs(this.vy / this.vx);
  315.    x = 260 + a;
  316.    y = k * x;
  317.    y0 = 195 + a;
  318.    if(y0 < y)
  319.    {
  320.       y = y0;
  321.       x = y / k;
  322.    }
  323.    if(this.vx < 0)
  324.    {
  325.       x = - x;
  326.    }
  327.    if(this.vy < 0)
  328.    {
  329.       y = - y;
  330.    }
  331.    this.pGo._x = 260 + x;
  332.    this.pGo._y = 195 + y;
  333.    with(this)
  334.    {
  335.       pGo._visible = true;
  336.       vx = - vx;
  337.       vy = - vy;
  338.       tmpI = Math.atan2(vx,vy) * mP;
  339.       pGo._rotation = - tmpI + 90;
  340.       st = 1;
  341.       pC = 0;
  342.    }
  343. };
  344. Wolf.prototype.goto = function()
  345. {
  346.    with(this)
  347.    {
  348.       if(sF)
  349.       {
  350.          return undefined;
  351.       }
  352.       if(st == 0)
  353.       {
  354.          if(dT < pC)
  355.          {
  356.             sGo();
  357.          }
  358.       }
  359.       else if(st == 1)
  360.       {
  361.          pGo._x += vx * cS;
  362.          pGo._y += vy * cS;
  363.          if(pT < pC)
  364.          {
  365.             pC = 0;
  366.             st = 2;
  367.             sF = true;
  368.             pGo._visible = false;
  369.             p._x = pGo._x;
  370.             p._y = pGo._y;
  371.             p._rotation = pGo._rotation;
  372.             p._visible = true;
  373.          }
  374.       }
  375.       else if(st == 2)
  376.       {
  377.          if(pT < pC)
  378.          {
  379.             pC = 0;
  380.             st = 1;
  381.             p._visible = false;
  382.             pGo._visible = true;
  383.          }
  384.       }
  385.    }
  386. };
  387. Wolf.prototype.sheepAm = function()
  388. {
  389.    with(this)
  390.    {
  391.       st = 3;
  392.       sF = true;
  393.       pC = 0;
  394.       p._visible = false;
  395.       pGo._visible = false;
  396.       p._x = pGo._x;
  397.       p._y = pGo._y;
  398.    }
  399.    nn.mc_topt1.duplicateMovieClip("pTpt1",2000 + this.pNum);
  400.    nn.pTpt1._x = this.p._x;
  401.    nn.pTpt1._y = this.p._y;
  402.    nn.pTpt1._rotation = this.p._rotation;
  403.    nn.pTpt1._visible = true;
  404.    nn.pTpt1.sender = this;
  405. };
  406. Wolf.prototype.pasAm = function()
  407. {
  408.    with(this)
  409.    {
  410.       st = 4;
  411.       sF = true;
  412.       pC = 0;
  413.       p._visible = false;
  414.       pGo._visible = false;
  415.       p._x = pGo._x;
  416.       p._y = pGo._y;
  417.    }
  418.    nn.mc_topt2.duplicateMovieClip("pTpt2",2500 + this.pNum);
  419.    nn.pTpt2._x = this.p._x;
  420.    nn.pTpt2._y = this.p._y;
  421.    nn.pTpt2._rotation = this.p._rotation;
  422.    nn.pTpt2._visible = true;
  423.    nn.pTpt2.sender = this;
  424.    nn._parent.eFlag = true;
  425. };
  426. Wolf.prototype.goToDie = function()
  427. {
  428.    with(this)
  429.    {
  430.       sF = true;
  431.       st = 0;
  432.       pC = 0;
  433.       pGo._x = pGo._y = p._x = p._y = -2000;
  434.       pGo._visible = p._visible = false;
  435.       glC = 0;
  436.    }
  437. };
  438. Wolf.prototype.next = function()
  439. {
  440.    with(this)
  441.    {
  442.       if(st == 3)
  443.       {
  444.          sF = true;
  445.          pC = 0;
  446.          st = 2;
  447.          p._visible = true;
  448.          pGo._visible = false;
  449.       }
  450.       else if(st == 4)
  451.       {
  452.          p._parent._parent.gameOver();
  453.       }
  454.    }
  455. };
  456. Wolf.prototype.hT = function(obj)
  457. {
  458.    if(this.st == 2)
  459.    {
  460.       if(this.p.c1.hitTest(obj))
  461.       {
  462.          return true;
  463.       }
  464.       if(this.p.c2.hitTest(obj))
  465.       {
  466.          return true;
  467.       }
  468.    }
  469.    else if(this.st == 1)
  470.    {
  471.       if(this.pGo.c1.hitTest(obj))
  472.       {
  473.          return true;
  474.       }
  475.       if(this.pGo.c2.hitTest(obj))
  476.       {
  477.          return true;
  478.       }
  479.    }
  480.    return false;
  481. };
  482. Wolf.prototype.hTo = function(obj)
  483. {
  484.    if(this.st == 2)
  485.    {
  486.       if(this.p.c1.hitTest(obj.pU.c))
  487.       {
  488.          return true;
  489.       }
  490.       if(this.p.c2.hitTest(obj.pU.c))
  491.       {
  492.          return true;
  493.       }
  494.    }
  495.    else if(this.st == 1)
  496.    {
  497.       if(this.pGo.c1.hitTest(obj.pU.c))
  498.       {
  499.          return true;
  500.       }
  501.       if(this.pGo.c2.hitTest(obj.pU.c))
  502.       {
  503.          return true;
  504.       }
  505.    }
  506.    return false;
  507. };
  508. Wolf.prototype.gluk = function()
  509. {
  510.    with(this)
  511.    {
  512.       st = 5;
  513.       sF = true;
  514.       pC = 0;
  515.       pGo._visible = p._visible = false;
  516.       p._x = pGl._x = pGo._x;
  517.       p._y = pGl._y = pGo._y;
  518.       pGl._visible = true;
  519.       pGl._rotation = pGo._rotation;
  520.    }
  521.    playSnd("lib_wattack");
  522. };
  523. Wolf.prototype.gluCheck = function()
  524. {
  525.    with(this)
  526.    {
  527.       if(st == 5)
  528.       {
  529.          if(glT < pC)
  530.          {
  531.             pC = 0;
  532.             st = 2;
  533.             p._visible = true;
  534.             pGo._visible = false;
  535.             pGl._visible = false;
  536.             pGl._x = pGl._y = -5000;
  537.             glC++;
  538.             if(glC == glA)
  539.             {
  540.                die();
  541.             }
  542.             return undefined;
  543.          }
  544.       }
  545.       else if(st == 6)
  546.       {
  547.          if(pC >= 3)
  548.          {
  549.             goToDie();
  550.          }
  551.       }
  552.    }
  553. };
  554. Wolf.prototype.die = function()
  555. {
  556.    with(this)
  557.    {
  558.       st = 6;
  559.       pC = 0;
  560.       sF = true;
  561.       p._visible = true;
  562.       pGo._visible = false;
  563.    }
  564.    nn.mc_boom.duplicateMovieClip("pBoom",6000 + this.numL);
  565.    with(nn.pBoom)
  566.    {
  567.       _visible = true;
  568.       _x = this.pGo._x;
  569.       _y = this.pGo._y;
  570.       _xscale = _yscale = 150;
  571.    }
  572.    set("/gametablo:scores",Number(eval("/gametablo:scores")) + scrWolf);
  573. };
  574. Man = function(parent, parentGo, parentShoot, parentFire)
  575. {
  576.    this.p = parent;
  577.    this.pG = parentGo;
  578.    this.pS = parentShoot;
  579.    this.pF = parentFire;
  580.    this.pU = this.p;
  581.    with(this)
  582.    {
  583.       pF._x = pF._y = pS._x = pS._y = -3000;
  584.       pF._visible = pG._visible = pS._visible = false;
  585.       pG._x = p._x;
  586.       pG._y = p._y;
  587.    }
  588.    pS.stop();
  589.    this.st = 0;
  590.    this.shA = false;
  591.    this.sh = false;
  592.    this.shF = false;
  593.    this.fr = false;
  594.    this.fx = this.p._x;
  595.    this.fy = this.p._y;
  596. };
  597. Man.prototype.goto = function(hit)
  598. {
  599.    with(this)
  600.    {
  601.       if(!hit)
  602.       {
  603.          pG._x = p._x = fx;
  604.          pG._y = p._y = fy;
  605.       }
  606.    }
  607. };
  608. Man.prototype.calcXY = function()
  609. {
  610.    with(this)
  611.    {
  612.       txa = Math.abs(tx = _xmouse - fx);
  613.       tya = Math.abs(ty = _ymouse - fy);
  614.       tr = txa + tya;
  615.       pG._rotation = p._rotation = (u = Math.atan2(tx,- ty)) * mP;
  616.       if(tr < 8)
  617.       {
  618.          if(st == 1)
  619.          {
  620.             st = 0;
  621.             pG._visible = false;
  622.             p._visible = true;
  623.             pU = p;
  624.          }
  625.          return undefined;
  626.       }
  627.       if(st == 0)
  628.       {
  629.          st = 1;
  630.          p._visible = false;
  631.          pG._visible = true;
  632.          pU = pG;
  633.       }
  634.       dY = min(int(tr - 8),10);
  635.       if(dY < 0.0001)
  636.       {
  637.          if(st == 1)
  638.          {
  639.             st = 0;
  640.             pG._visible = false;
  641.             p._visible = true;
  642.             pU = p;
  643.          }
  644.       }
  645.       fx = p._x + dY * Math.sin(u);
  646.       fy = p._y - dY * Math.cos(u);
  647.       if(0 >= fx)
  648.       {
  649.          fx = 0;
  650.       }
  651.       if(520 < fx)
  652.       {
  653.          fx = 520;
  654.       }
  655.       if(0 >= fy)
  656.       {
  657.          fy = 0;
  658.       }
  659.       if(390 < fy)
  660.       {
  661.          fy = 390;
  662.       }
  663.    }
  664. };
  665. Man.prototype.shoot = function()
  666. {
  667.    with(this)
  668.    {
  669.       pG._visible = p._visible = false;
  670.       pS.duplicateMovieClip("pShoot",3000);
  671.       nn.pShoot._visible = true;
  672.       nn.pShoot._x = p._x;
  673.       nn.pShoot._y = p._y;
  674.       nn.pShoot._rotation = p._rotation;
  675.       nn.pShoot.sender = this;
  676.       pU = nn.pShoot;
  677.       shA = true;
  678.    }
  679.    playSnd("lib_knut");
  680. };
  681. Man.prototype.endSh = function()
  682. {
  683.    if(st == 2)
  684.    {
  685.       return undefined;
  686.    }
  687.    with(this)
  688.    {
  689.       shA = false;
  690.       if(st == 0)
  691.       {
  692.          p._visible = true;
  693.          pU = p;
  694.       }
  695.       else
  696.       {
  697.          pG._visible = true;
  698.          pU = pG;
  699.       }
  700.    }
  701. };
  702. Man.prototype.fire = function()
  703. {
  704.    with(this)
  705.    {
  706.       pG._visible = p._visible = false;
  707.       pF.duplicateMovieClip("pFire",3000);
  708.       nn.pFire._visible = true;
  709.       nn.pFire._x = p._x;
  710.       nn.pFire._y = p._y;
  711.       nn.pFire._rotation = p._rotation;
  712.       nn.pFire.sender = this;
  713.       pU = nn.pFire;
  714.       shF = true;
  715.    }
  716.    playSnd("lib_shoot");
  717. };
  718. Man.prototype.endF = function()
  719. {
  720.    if(st == 2)
  721.    {
  722.       return undefined;
  723.    }
  724.    with(this)
  725.    {
  726.       shF = false;
  727.       if(st == 0)
  728.       {
  729.          p._visible = true;
  730.          pU = p;
  731.       }
  732.       else
  733.       {
  734.          pG._visible = true;
  735.          pU = pG;
  736.       }
  737.    }
  738. };
  739. Man.prototype.hTf = function(obj)
  740. {
  741.    if(Math.abs(this.fx - obj.fx) < h2 + 14 && Math.abs(this.fy - obj.fy) < h2 + 14)
  742.    {
  743.       return true;
  744.    }
  745.    return false;
  746. };
  747. Man.prototype.hT = function(obj)
  748. {
  749.    if(Math.abs(this.fx - obj._x) < h2 + 14 && Math.abs(this.fy - obj._y) < h2 + 14)
  750.    {
  751.       return true;
  752.    }
  753.    return false;
  754. };
  755. Man.prototype.die = function()
  756. {
  757.    with(this)
  758.    {
  759.       p._x = p._y = pG._x = pG._y = -3000;
  760.       p._visible = pG._visible = false;
  761.       st = 2;
  762.    }
  763.    nn.pFire._visible = nn.pShoot._visible = false;
  764. };
  765.